package com.uw.uwrpc.core.api;

import com.uw.uwrpc.core.consumer.ConsumerInvoker;
import com.uw.uwrpc.core.meta.InstanceMeta;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RpcContext {
    private List<Filter> filterList;
    private Router<InstanceMeta> router;
    private LoadBalancer<InstanceMeta> loadBalancer;
    private ConsumerInvoker consumerInvoker;

    private Map<String, String> parameters = new HashMap<>();


    public static ThreadLocal<Map<String, String>> contextParam = ThreadLocal.withInitial(HashMap::new);

    public static void putContextParam(String key, String value) {
        contextParam.get().put(key, value);
    }

    public static String getContextParam(String key) {
        return contextParam.get().get(key);
    }

    public static Map<String, String> getContextParam() {
        return contextParam.get();
    }

    public static void clearContext() {
        contextParam.get().clear();
    }
}
